﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LWH.ByteProtocol
{
    /// <summary>
    /// 多选一形式的property，类似于switch
    /// 功能类似于PackageProperty，是对实际属性对象的包装
    /// 这里switch的实现有2种方案，1是对实际属性的完全转发
    /// 2是作为对象的包装，跟PackageProperty相似
    /// 这里采用第2种方案，主要是因为方案2更严格遵循层叠
    /// 结构
    /// </summary>
    public abstract class SwitchProperty:OwnerProperty
    {
        public SwitchProperty(OwnerProperty ownerProperty) : base(ownerProperty)
        {
        }

        public abstract SkeletalProperty getProperty();



        public override bool handleProperty(Dictionary<String, Object> context)
        {
            return getProperty().handleProperty(context);
        }

        public override int getLength()
        {
            return getProperty().getLength();
        }



        public override byte[] getData()
        {
            return getProperty().getData();
        }

        public override void setData(byte[] data, int offset, int length)
        {
            getProperty().setData(data, offset, length);
        }

        protected internal override int getPropertyOffset(AbstractProperty property)
        {
            return 0;
        }

        public override void addProperty(AbstractProperty property)
        {
            property.setIndex(0);
        }
    }
}
